<style>
    #title {
        padding: 3px 8px;
        width: 100%;
        font-size: 1.6em;
    }
</style>

<form action="post.php?action=save" method="post" class="cmd-async">
    <h1 class="page-header"><?php echo $header; ?></h1>
    <div class="row">
        <div class="col-md-10">
            <p><input id="title" type="text" name="post_title" placeholder="在此输入标题"
                      value="<?php echo $post['post_title']; ?>"></p>
            <textarea name="post_content" id="post_content" style="display: none">
                <?php echo $post['post_content']; ?>
            </textarea>
        </div>
        <div class="col-md-2">
            <div class="form-group">
            <a onclick="save(<?php echo POST_STATUS_PUBLISH ?>);" class="btn btn-block btn-primary"><span class="glyphicon glyphicon-ok">发布</a>
            <a onclick="save(<?php echo POST_STATUS_DRAFT ?>);" class="btn btn-block btn-primary"><span class="glyphicon glyphicon-floppy-save"></span>保存草稿</a>
            <?php if (!empty($post['id'])): ?>
                <a href="post.php?action=delete&id=<?php echo $post['id']; ?>" data-confirm="确定删除?"
                   class="btn btn-block btn-danger cmd-post"><span class="glyphicon glyphicon-remove"></span>删除</a>
            <?php endif; ?>
            </div>

            <div class="form-group">
            <label for="category_id">选择分类</label>
                <?php echo html_select_render(category_all(), '', array(
                    'name' => 'category_id',
                    'class' => 'form-control',
                    'selected' => $post['category_id'],
            )); ?>
            </div>

            <div class="form-group">
                <label for="tag">标签<span class="glyphicon glyphicon-question-sign" data-toggle="tooltip" title="多个标签用英文逗号隔开"></span></label>
                <input type="text" id="tag" name="tag" class="form-control" value="<?php e($post['tag']); ?>">
            </div>

            <div class="form-group">
                <label for="post_password">访问密码</label>
                <input type="password" id="post_password" name="post_password" class="form-control" value="<?php e($post['post_password']); ?>">
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="comment_status"
                           value="<?php echo COMMENT_STATUS_OPEN; ?>" <?php if ($post['comment_status'] == COMMENT_STATUS_OPEN) echo 'checked="checked"'; ?>> 允许评论
                </label>
            </div>
        </div>
    </div>
    <input type="hidden" name="post_status" id="post_status">
    <input type="hidden" name="id" value="<?php echo $post['id']; ?>">
    <?php echo csrf_token_hidden_input_html() ?>
</form>
<script src="<?php assets_url('libs/ckeditor/ckeditor.js'); ?>"></script>
<script>
    var config = {
        language: 'zh-cn',
        uploadUrl: 'upload.php',
        filebrowserBrowseUrl: '../imageuploader/imgbrowser.php'
    };

    config.toolbarGroups = [
        {name: 'clipboard', groups: ['clipboard', 'undo']},
        {name: 'editing', groups: ['find', 'selection', 'spellchecker', 'editing']},
        {name: 'forms', groups: ['forms']},
        {name: 'basicstyles', groups: ['basicstyles', 'cleanup']},
        {name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph']},
        {name: 'links', groups: ['links']},
        {name: 'insert', groups: ['insert']},
        {name: 'styles', groups: ['styles']},
        {name: 'colors', groups: ['colors']},
        {name: 'tools', groups: ['tools']},
        {name: 'others', groups: ['others']},
        {name: 'about', groups: ['about']},
        {name: 'document', groups: ['document', 'mode', 'doctools']}
    ];

    config.removeButtons = 'Save,NewPage,Print,Templates,Cut,Copy,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Subscript,Superscript,RemoveFormat,CreateDiv,BidiLtr,BidiRtl,Language,Styles,ShowBlocks,About';

    config.extraPlugins = 'autogrow';
    config.autoGrow_minHeight = 200;
    config.autoGrow_maxHeight = 600;

    var editor = CKEDITOR.replace('post_content', config);

    function save(status) {
        $('#post_status').val(status);
        $('#post_content').val(editor.getData());
        $('form').submit();
    }

</script>